﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    //2、猫、狗、鸭、猴，（吃、游泳、爬树）
    class Animal
    {
        private string name;
        private string sex;

        public string Sex { get => sex; set => sex = value; }
        public string Name { get => name; set => name = value; }
        public Animal(string name, string sex)
        {
            this.name = name;
            this.sex = sex;
        }
        public Animal()
        {
        }
    }
    interface IClimb
    {
        void Climb();
    }
    interface IEat
    {
        void Eat();
    }
    interface ISwim
    {
        void Swim();
    }
    class Cat : Animal, IClimb, IEat, ISwim
    {
        public void Climb()
        {
            Console.WriteLine("猫爬树");
        }
        public void Eat()
        {
            Console.WriteLine("猫吃粮");
        }
        public void Swim()
        {
            Console.WriteLine("猫游泳");
        }
        public void Play()
        {
            Console.WriteLine("名字叫{0}，性别为{1}的小猫正在玩毛球",this.Name,this.Sex);
        }
        public Cat(string name, string sex) : base(name, sex)
        {

        }
    }
    class Dog : Animal, ISwim, IEat
    {
        public void Swim()
        {
            Console.WriteLine("狗在狗刨游泳");
        }
        public void Eat()
        {
            Console.WriteLine("狗吃粮");
        }
        public void Play()
        {
            Console.WriteLine("名字叫{0}，性别为{1}的小狗正在捡木棍", this.Name, this.Sex);
        }
        public Dog(string name, string sex) : base(name, sex)
        {

        }
    }
    class Duck : Animal, ISwim, IEat
    {
        public void Swim()
        {
            Console.WriteLine("鸭子游泳");
        }
        public void Eat()
        {
            Console.WriteLine("鸭子吃饭");
        }
        public void Play()
        {
            Console.WriteLine("名字叫{0}，性别为{1}的小鸭正在玩水", this.Name, this.Sex);
        }
        public Duck(string name, string sex) : base(name, sex)
        {

        }
    }
    class Monkey : Animal, IClimb, IEat
    {
        public void Climb()
        {
            Console.WriteLine("猴子爬树");
        }
        public void Eat()
        {
            Console.WriteLine("猴子吃桃");
        }
        public void Play()
        {
            Console.WriteLine("名字叫{0}，性别为{1}的小猴正在荡秋千", this.Name, this.Sex);
        }
        public Monkey(string name, string sex) : base(name, sex)
        {

        }

    }
    class Program1
    {
        static void TestSwin(ISwim swim)
        {
            swim.Swim();
        }

        static void TestClimb(IClimb climb)
        {
            climb.Climb();
        }
        static void TestEat(IEat eat)
        {
            eat.Eat();
        }
        static void Main(string[] args)
        {
            Cat cat = new Cat("小咪","母");
            Dog dog = new Dog("旺财","公");
            Monkey monkey = new Monkey("泼猴", "公");
            Duck duck = new Duck("呆鸭", "母");
            TestClimb(cat);
            TestEat(cat);
            TestSwin(cat);
            cat.Play();
            Console.WriteLine();
            TestEat(dog);
            TestSwin(dog);
            dog.Play();
            Console.WriteLine();
            TestEat(duck);
            TestSwin(duck);
            duck.Play();
            Console.WriteLine();
            TestClimb(monkey);
            TestEat(monkey);
            monkey.Play();
            //TestAnimal(cat);
            //TestAnimal(dog);

            //Animal a = cat;
            //cat = (Cat)a;
            Console.ReadKey();
        }
        
        //static void TestAnimal(Animal a)
        //{
        //    a.Eat();
        //}
    }
    }

